package leetcode_core.leetcode_5;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年01月04日 11:59
 */
public class IsIsomorphic {
    public boolean isIsomorphic(String s, String t) {
        int sLen = s.length();
        int tLen = t.length();
        if(sLen != tLen){
            return false;
        }
        Map<Character,Character> s2t = new HashMap<>();
        Map<Character,Character> t2s = new HashMap<>();
        int len = s.length();
        for(int i = 0;i<len;i++){
            char a = s.charAt(i);
            char b = t.charAt(i);
            if(s2t.containsKey(a) && s2t.get(a) != b ){
                return false;
            }
            if(t2s.containsKey(b) && t2s.get(b) != a){
                return false;
            }
            s2t.put(a,b);
            t2s.put(b,a);
        }
        return true;
    }
}
